package com.example.onlinemusicserver2024.controller;

import com.example.onlinemusicserver2024.common.R;
import com.example.onlinemusicserver2024.model.domain.Collect;
import com.example.onlinemusicserver2024.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class CollectController {


    @Autowired
    CollectService collectService;

    /**
     * 根据用户ID查询收藏的歌曲
     *
     * @return
     */
    // http://localhost:8888/collection/detail?user_id=1
    @GetMapping("/collection/detail")
    public R collectionOfUser(@RequestParam int userId) {
        System.out.println("查询收藏的歌曲：userId=" + userId);
        R result = collectService.collectionOfUser(userId);
        return result;
    }

    /**
     * 收藏歌曲
     *
     * @param collect
     * @return
     */
    @PostMapping("/collection/add")
    public R addCollection(@RequestBody Collect collect) {
        R result = collectService.addCollection(collect);
        return result;
    }

    /**
     * 获取歌曲的收藏状态
     *
     * @param collect
     * @return
     */
    @PostMapping("/collection/status")
    public R getCollectionStatus(@RequestBody Collect collect) {
        R result = collectService.getCollectionStatus(collect);
        return result;
    }

    @DeleteMapping("/collection/delete")
    public R deleteCollection(@RequestParam int userId, @RequestParam int songId) {
        R result = collectService.deleteCollection(userId,songId);
        return result;
    }
}
